﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using SWC=System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Reporting.WinForms;
using SQLServerOptimizer.PL.WPF.Datasets.IssuesReportDatasetTableAdapters;
using System.Configuration;
using SQLServerOptimizer.PL.WPF.Datasets;
using System.Windows.Forms;
using AG.Utilities;
using SQLServerHealthCheck.Model;
using SQLServerHealthCheck.SQLServer;
using SQLServerHealthCheck.PL.DataSetDatabaseTraceDetailsTableAdapters;
using SQLServerHealthCheck.PL;
namespace SQLServerOptimizer.PL.WPF
{

    public partial class DatabaseTraceDetailsReportControl : SWC.UserControl
    {

        public int DatabaseTraceID { get; set; }

        public DatabaseTraceDetailsReportControl()
        {
            InitializeComponent();
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {

        }        


        public void RefreshReport()
        {

            try
            {
                ReportViewer viewer = (ReportViewer)wfh_rptDatabaseTraces.Child;

                DatabaseTraceDetailsTableAdapter adapter = new DatabaseTraceDetailsTableAdapter();
                adapter.Connection.ConnectionString = ConfigurationManager.AppSettings["ConnectionStringSSHCDatabase"];


                DataSetDatabaseTraceDetails dataset = new DataSetDatabaseTraceDetails();

                adapter.Fill(dataset.DatabaseTraceDetails, DatabaseTraceID);


                BindingSource bindingSource = new BindingSource();

                bindingSource.DataSource = dataset;
                bindingSource.DataMember = "DatabaseTraceDetails";


                ReportDataSource reportDataSource = new ReportDataSource();
                viewer.Reset();

                reportDataSource.Name = "DataSetDatabaseTraceDetails";
                reportDataSource.Value = bindingSource;

                viewer.LocalReport.DataSources.Add(reportDataSource);
                viewer.LocalReport.EnableHyperlinks = true;
                viewer.BorderStyle = BorderStyle.None;


                viewer.LocalReport.ReportPath = System.Windows.Forms.Application.StartupPath + @"\Reports\DatabaseTraceDetails.rdlc";
                viewer.RefreshReport();




            }

            catch (Exception ex)
            {
                Logger.Error(ex);
            }





        }

        private void wfh_rptDatabaseTraces_LayoutError(object sender, System.Windows.Forms.Integration.LayoutExceptionEventArgs e)
        {

            e.ThrowException = false;
        
        }

        
        
    }
}
